package com.m1905hd.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author weiwei.huang
 * @email ihuangweiwei@163.com
 * @date 15/3/30
 */
public class Resource {
    private int id;
    private String name;
    private ResourceType type = ResourceType.menu;
    private String url;
    private String permission;
    private int parentId;
    private String parentIds;
    private int position;
    private int available = 1;

    private List<Resource> childResource = new ArrayList<>();


    public enum ResourceType {
        menu("菜单"), button("按钮"), nav("导航"), second_nav("二级导航");

        private final String info;

        ResourceType(String info) {
            this.info = info;
        }

        public String getInfo() {
            return info;
        }


        public static ResourceType get(String info) {
            if (info.equals(menu.name())) {
                return ResourceType.menu;
            }
            if (info.equals(button.name())) {
                return ResourceType.button;
            }
            if (info.equals(nav.name())) {
                return ResourceType.nav;
            }
            if (info.equals(second_nav.name())) {
                return ResourceType.second_nav;
            }
            return null;
        }
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ResourceType getType() {
        return type;
    }

    public void setType(String type) {
        this.type = ResourceType.get(type);
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public int getParentId() {
        return parentId;
    }

    public void setParentId(int parentId) {
        this.parentId = parentId;
    }

    public String getParentIds() {
        return parentIds;
    }

    public void setParentIds(String parentIds) {
        this.parentIds = parentIds;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public int getAvailable() {
        return available;
    }

    public void setAvailable(int available) {
        this.available = available;
    }

    public List<Resource> getChildResource() {
        return childResource;
    }

    public void setChildResource(List<Resource> childResource) {
        this.childResource = childResource;
    }

    @Override
    public String toString() {
        return "Resource{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", type=" + type +
                ", url='" + url + '\'' +
                ", permission='" + permission + '\'' +
                ", parentId=" + parentId +
                ", parentIds='" + parentIds + '\'' +
                ", position=" + position +
                ", available=" + available +
                ", childResource=" + childResource +
                '}';
    }
}
